import { api } from "../api"

export function fetchCoursesApi(searchValue: string) {
  try {
    if (searchValue === null || searchValue === "") {
      return api.get('/java/teacher/StudySpaceTeacher/getCourse', {
      });
    }
    return api.get('/java/teacher/StudySpaceTeacher/getCourse', {
      params: { sentence: searchValue },
    });
  }
  catch (error) {
    throw new Error('获取课程列表失败');
  }
}

export function createCoursesApi(courseFormData: any) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/createCourse', courseFormData);
  }
  catch (error) {
    throw new Error('创建新课程失败');
  }
}

export function deleteCoursesApi(courseId: string, courseFileId: string) {
  try {
    return api.get('/java/teacher/StudySpaceTeacher/deleteFiles', {
      params: {
        courseId,
        courseFileId,
      },
    })
  }
  catch (error) {
    throw new Error('删除课程失败');
  }
}
export function fetchCourseInformationApi(courseId: string | null) {
  try {
    return api.get('/java/ground/study/course/get_course_information_by_id', {
      params: { courseId },
    })
  }
  catch (error) {
    throw new Error('删除课程失败');
  }
}
export function modifyCourseInformationApi(courseFormData: any) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/modify_course', courseFormData);
  }
  catch (error) {
    throw new Error('删除课程失败');
  }
}
